package com.atbeijing.D07;

import org.apache.flink.api.java.functions.KeySelector;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class Example2 {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        env
                .fromElements(1,2,3,4,5,6)
                .keyBy(new KeySelector<Integer, Boolean>() {
                    //对2取余,返回true的在一条流,返回false的在一条流
                    @Override
                    public Boolean getKey(Integer value) throws Exception {
                        return value%2==0;
                    }
                })
                .sum(0)
                .print();

        env.execute();
    }
}
